package com.twu.biblioteca.menu;

import com.twu.biblioteca.*;

public class ListBooksMenuItem implements MenuItem {
    @Override
    public String getName() {
        return "List Books";
    }

    @Override
    public String getMnemonic() {
        return "bl";
    }

    @Override
    public PostMenuItemAction execute(Library library, UserIO io, UserRepository repository) {
        io.println("Books available:");
        int booksAvailable = 0;

        for (Book book : library.getBooks()) {
            if (!book.isCheckedOut()) {
                io.println(String.format("%-50s %-30s %s", book.getTitle(), book.getAuthor(), book.getYearPublished()));
                booksAvailable++;
            }
        }

        if (booksAvailable == 0) {
            io.println("There are no books available.");
        }

        return PostMenuItemAction.Continue;
    }

    @Override
    public boolean shouldDisplay(User currentUser) {
        return true;
    }

    @Override
    public int getPriority() {
        return MenuItem.PRIORITY_BOOKS;
    }
}
